<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import studentDashboard from './student'
import teacherDashboard from './teacher'

export default {
  name: 'Dashboard',
  components: { adminDashboard, studentDashboard, teacherDashboard },
  data() {
    return {
      currentRole: 'adminDashboard'
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    // 因为目前的需求roles只有一个元素，所以对直判断赋值就最方便
    if (this.roles.includes('admin')) {
      this.currentRole = 'adminDashboard'
    }
    if (this.roles.includes('student')) {
      this.currentRole = 'studentDashboard'
    }
    if (this.roles.includes('teacher')) {
      this.currentRole = 'teacherDashboard'
    }
  }
}
</script>
